/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.wx.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.wx.entity.WxActivityTheme;
import com.jeesite.modules.wx.service.WxActivityThemeService;

import java.util.List;

/**
 * wx_activity_themeController
 * @author wangjianxin
 * @version 2018-09-28
 */
@Controller
@RequestMapping(value = "${adminPath}/wx/wxActivityTheme")
public class WxActivityThemeController extends BaseController {

	@Autowired
	private WxActivityThemeService wxActivityThemeService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public WxActivityTheme get(String id, boolean isNewRecord) {
		return wxActivityThemeService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("wx:wxActivityTheme:view")
	@RequestMapping(value = {"list", ""})
	public String list(WxActivityTheme wxActivityTheme, Model model) {
		model.addAttribute("wxActivityTheme", wxActivityTheme);
		return "modules/wx/wxActivityThemeList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("wx:wxActivityTheme:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<WxActivityTheme> listData(WxActivityTheme wxActivityTheme, HttpServletRequest request, HttpServletResponse response) {
		Page<WxActivityTheme> page = wxActivityThemeService.findPage(new Page<WxActivityTheme>(request, response), wxActivityTheme);
		List<WxActivityTheme> wxActivityThemeList = page.getList();
		for(WxActivityTheme temp : wxActivityThemeList){
			if(temp.getTheme().equals("1")){
				temp.setTheme("主题一");
			}else if(temp.getTheme().equals("2")){
				temp.setTheme("主题二");
			}else if(temp.getTheme().equals("3")){
				temp.setTheme("主题三");
			}
		}
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("wx:wxActivityTheme:view")
	@RequestMapping(value = "form")
	public String form(WxActivityTheme wxActivityTheme, Model model) {
		model.addAttribute("wxActivityTheme", wxActivityTheme);
		return "modules/wx/wxActivityThemeForm";
	}

	/**
	 * 保存wx_activity_theme
	 */
	@RequiresPermissions("wx:wxActivityTheme:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated WxActivityTheme wxActivityTheme) {
		wxActivityThemeService.save(wxActivityTheme);
		return renderResult(Global.TRUE, text("保存wx_activity_theme成功！"));
	}
	
	/**
	 * 删除wx_activity_theme
	 */
	@RequiresPermissions("wx:wxActivityTheme:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(WxActivityTheme wxActivityTheme) {
		wxActivityThemeService.delete(wxActivityTheme);
		return renderResult(Global.TRUE, text("删除wx_activity_theme成功！"));
	}
	
}